import request from "@/util/request"
import { API_SITE, API_PREFIX } from "./_prefix"

/**
 * 根据userId获得邮件任务
 */
export const getMailTaskByUserId = (userId,status = -1) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/mailtask?status=${status}`)
}

/**
 * 启动已保存邮件任务
 */
// export const startMailTask = (userId, mailTaskId) => {
//     request(`${API_SITE}${API_PREFIX}/${userId}/mailtask/${mailTaskId}/start`,{
//         method: "POST"
//     })
// }

/**
 * 启动邮件任务
 */
export const startMailTask = (userId,{content, subjects,fromMailId, mailTos, intervalInSeconds, sleepInterval, replyTo, sleepEveryNLetters, customerTypeId, type}) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/mailtask/start`,{
        method: "POST",
        body: {
            content: content,
            fromMailId: fromMailId,
            subjects: subjects,
            mailTos: mailTos,
            intervalInSeconds: intervalInSeconds,
            sleepInterval: sleepInterval,
            replyTo: replyTo,
            sleepEveryNLetters: sleepEveryNLetters,
            customerTypeId: customerTypeId,
            type: type,
        }
    })
}

/**
 * 停止邮件任务
 */
export const stopMailTask = (userId,mailTaskId) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/mailtask/${mailTaskId}/stop`,{
        method: "POST",
    })
}

/**
 * 新建邮件任务
 */
export const createMailTask = (userId,mailTaskDTO) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/mailtask`,{
        method: "POST",
        body: {
            mailTaskDTO
        }
    })
}

/**
 * 更新邮件任务
 */
export const updateMailTask = (userId,mailTaskId,mailTaskDTO) => {
    return request(`${API_SITE}${API_PREFIX}/${userId}/mailtask/${mailTaskId}`,{
        method: "POST",
        body: {
            mailTaskDTO
        }
    })
}